/**
 * Just For send message, and call by C
 */
package com.iptv.epg;

import com.ihome.android.market2.frag.RecommAppFragmentEdu;

import android.media.MediaPlayer;
import android.os.Message;
import android.util.Log;

//import com.iptv.common.Common;
//import com.iptv.common.IPTVConfig;
//import com.iptv.player.IPTVPlayer;

public class Inform {

	public static String currentUrl = "";
	public static String currentUrlOrig = "";

	public static void setUrl(String str) {
		Log.i("SuIPTV", "hust url from c++: " + str);
		currentUrlOrig = str;
		// ULog.i("SuIPTV", "hust current url: " + str);
		if (isVirtualPage(str)) {
			return;
		}
		currentUrl = str;

/*		if (currentUrl.contains("frameset_builder")) {
			IPTVConfig.isAuthComplete = true;
			Inform.sendMessage(Common.MSG_RemoveStartPic);
		}

		if (currentUrl.contains("/iptvepg/frame129/portal.jsp")
				|| currentUrl.contains("/iptvepg/frame183/frame_portal.jsp")
				|| currentUrl.contains("/iptvepg/frame69/portal.jsp")) {
			Inform.sendMessage(Common.MSG_RemoveStartPic);
			IPTVConfig.isAuthComplete = true;
		}
		if (currentUrl.contains("/iptvepg/frame129/portal.jsp")) {
			IPTVConfig.inWhichServer = IPTVConfig.GuangDian;
		} else if (currentUrl.contains("/iptvepg/frame69/portal.jsp")) {
			IPTVConfig.inWhichServer = IPTVConfig.BaiShiTong;
		} else if (currentUrl.contains("/iptvepg/frame205/portal.jsp")) {
			IPTVConfig.inWhichServer = IPTVConfig.BaiShiTongHD;
		}*/
	}

	// page not show, page in background
	public static boolean isVirtualPage(String str) {
/*		if (str.contains(Common.HeartBeatUrl) || str.contains("about:blank")
				|| str.contains("empty.jsp")
				|| str.contains("/iptvepg/frame212/getAndroidUserInfo.jsp")) {
			return true;
		}*/
		return false;
	}

	public static boolean isSDPage() {// 标清
/*		if (Inform.currentUrl.contains("/iptvepg/js22/") && IPTVConfig.isHD
				&& IPTVPlayer.getIsLive() == false) {
			return false;
		}*/
		if (Inform.currentUrl.contains("/iptvepg/frame129/portal.jsp")
				|| Inform.currentUrl.contains("/iptvepg/frame191/")
				|| Inform.currentUrl.contains("/iptvepg/frame183/")
				|| Inform.currentUrl.contains("/iptvepg/frame185/")
				|| Inform.currentUrl.contains("/iptvepg/frame69/")
				|| Inform.currentUrl.contains("/iptvepg/frame68/")
				|| Inform.currentUrl.contains("/iptvepg/js22/")
				|| Inform.currentUrl.contains("_game.jsp")
				|| Inform.currentUrl.contains("/vasroot/frame/")) {
			return true;
		}
		return false;
	}

	public static boolean isHDPage() {// 高清
		if (Inform.currentUrl.contains("/iptvepg/frame181")
				|| Inform.currentUrl.contains("/iptvepg/frame210"))
			return true;
		return false;
	}

	public static boolean isVodPauseUrl() {
//		return currentUrl.contains(Common.VodPauseUrl);
		return false;
	}

	public static boolean isVodPreauthUrl() {
		// 包含收藏按钮的视频页面
		if (Inform.currentUrl
				.contains("/iptvepg/frame129/vod_del_favorite.jsp")
				|| Inform.currentUrl
						.contains("/iptvepg/frame129/get_vod_favorite.jsp")
				|| Inform.currentUrl
						.contains("/iptvepg/frame129/vod_add_favorite.jsp")
				|| Inform.currentUrl
						.contains("/iptvepg/frame129/vod_preauth.jsp")) {
			return true;
		}

		return false;
	}

	public static boolean needSubmit() {
		// Node contains onSubmit event
		if (currentUrl.contains("/action/conversion")) {
			return true;
		}
		return false;
	}

	public static void RetryOrWait(int stateCode) {
		switch (stateCode) {
		case 1:
			Log.i("no302", "showtips!");
			// if(MediaPlayer.isPlaying)
			// Inform.showTips("系统繁忙，请稍后再试！");
			break;
		case 2:// 视频解码芯片启动失败
				// if(MediaPlayer.isPlaying)
				// Inform.showTips("视频暂时不能播放，请重试，或重新启动机顶盒！");
				// break;
		case 3:
			
			Inform.showTips("单播或组播首次请求失败！");
			//turn to unicast
			
//			IPTVPlayer.playerHandler.sendEmptyMessage(IPTVPlayer.StopPlay);
			
/*			Message msg = new Message();
			msg.what = IPTVPlayer.SetProgramUrl;
//			msg.obj = "rtsp://180.100.0.19:8089/zte/itv/01030500000000000000000000000001?AuthInfo=";
			msg.obj = "rtsp://58.223.255.214:554/live/ch13032914415327379939.sdp?playtype=1&boid=001&backupagent=58.223.255.214:554&clienttype=1&time=20140605094616+08&life=172800&ifpricereqsnd=1&vcdnid=vcdn001&userid=httest&mediaid=ch13032914415327379939&ctype=2&TSTVTimeLife=14400&contname=&authid=0&UserLiveType=1&nodelevel=3&usercharge=662355C7314DCDE59F10C090FE716AE2";
			IPTVPlayer.playerHandler.sendMessage(msg);
						
			IPTVPlayer.playerHandler.sendEmptyMessageDelayed(IPTVPlayer.StartPlay, 2*1000);*/
			break;
			
			
//			// Inform.showTips("Re Start");
//			// 获取videoId/audioId失败的时候，重试
//			if (IPTVConfig.VideoRetryTime < 5) {
//				IPTVConfig.VideoRetryTime++;
//				IPTVPlayer.playerHandler.sendEmptyMessage(IPTVPlayer.StartPlay);
//			} else {
//				if (stateCode == 2) {
//					Inform.showTips("视频暂时不能播放，请重试，或重新启动机顶盒！");
//				} else if (stateCode == 3) {
//					Inform.showTips("视频服务器繁忙，请稍后再试！");
//				}
//			}
//			break;
			
			
			
		case 461:
//			IPTVPlayer.playerHandler.sendEmptyMessage(IPTVPlayer.StartPlay);
			break;
		default:
			break;
		}

	}

	public static void playToMediaEnd() {
		// if(MediaPlayer.isPlaying && MediaPlayer.mp_videoDisplayMode==1) {
/*		if (IPTVPlayer.getIsLive()) {
			// showTips("快进到头，转为直播");
			// Inform.sendMessage(Common.MSG_REMOVE_SHIYIIMG);
			// Inform.sendMessage(Common.MSG_PLAY_Begining);
//			MediaPlayer.joinChannelFromTimeShift();
		} else {
			Inform.sendMessage(Common.MSG_PLAY_END);
		}*/
		RecommAppFragmentEdu.mHandler.sendEmptyMessageDelayed(RecommAppFragmentEdu.MSG_VIDEO_PLAY_END, 500);
		Log.i("SuIPTV", "[Inform:playEnd]");
		// }
	}

	public static void playToMediaBegining() {
		// if (MediaPlayer.isPlaying && MediaPlayer.mp_videoDisplayMode == 1) {
/*		if (IPTVPlayer.getIsLive()) {
			// showTips("已快退到头");
			Inform.sendMessage(Common.MSG_PLAY_Begining);
		} else {
			// showTips("已到视频开始处");
			Inform.sendMessage(Common.MSG_PLAY_Begining);
		}*/
		Log.i("SuIPTV", "[Inform:playToMediaBegining]");
		// }
	}

	public static void sendMessage(int msg_code) {
		Message msg2 = new Message();
		msg2.what = msg_code;
//		SyIPTV.MyHandler.sendMessage(msg2);
		// ULog.i("SuIPTV", "[Inform:sendMessage] " + msg_code);
	}

	public static void sendMessageDelayed(int msg_code, long delayMillis) {
		Message msg2 = new Message();
		msg2.what = msg_code;
//		SyIPTV.MyHandler.sendMessageDelayed(msg2, delayMillis);
		// ULog.i("SuIPTV", "[Inform:sendMessage] " + msg_code);
		
	}

	public static void showNoticeView() {
		Log.d("game", "showGameTips");
/*		Inform.sendMessage(Common.MSG_SHOW_NOTICEVIEW);
		Inform.sendMessage(Common.MSG_JS_GoBack);*/
	}

	public static void showTips(String tips) {
/*		Message msg = new Message();
		msg.what = Common.MSG_SHOW_TIPS;
		msg.obj = tips;*/
		
		Log.d("InformMsg", "tips:"+tips);
//		SyIPTV.MyHandler.sendMessage(msg);

	}
}
